package com.dchh.android.suverynew.module.local.impl;

import com.dchh.android.suverynew.module.local.ITzpPhotoMoudle;
import com.dhcc.android.base.common.bean.ImageInfoBean;
import com.dhcc.android.base.db.DBManagerUtil;
import com.dhcc.android.base.utils.PhotoUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by eric on 2016/8/14.
 */
public class TzpPhotoMoudle implements ITzpPhotoMoudle {
    private TzpPhotoMoudleListener moudleListener;

    public TzpPhotoMoudle(TzpPhotoMoudleListener moudleListener) {
        this.moudleListener = moudleListener;
    }

    @Override
    public void getInitData(int type, String taskName, String CUNMING, String dcqb,
                            String YFBHU, String tableName, String dbPath,
                            DBManagerUtil dbManagerUtil, PhotoUtil photoUtil) {
        List<String> keys = new ArrayList<String>();
        List<Map<String, String>> datas;
        if (keys.size() == 0) {
            keys.add("FILENAME");
            keys.add("LON");
            keys.add("LAT");
            keys.add("DATE");
            keys.add("村级行政区名称");
            keys.add("样方编号");
            keys.add("自然地块编号");
            keys.add("主要地物");
            keys.add("备注");
            keys.add("DCQB");
            keys.add("TYPE");
            keys.add("COUNTY");
        }
        String where = "DCQB = '" + dcqb + "' and TYPE = '" + type + "'";
        if (type == 1) {
            String val = taskName;
            datas = dbManagerUtil.getListData(tableName, keys, "COUNTY", val, where, dbPath);
        } else if (type == 2) {
            String val = CUNMING;
            datas = dbManagerUtil.getListData(tableName, keys, "村级行政区名称", val, where, dbPath);
        } else {
            String val = YFBHU;
            datas = dbManagerUtil.getListData(tableName, keys, "样方编号", val, "DCQB = '" + dcqb + "' and TYPE = '" + type + "'", dbPath);
        }
        List<ImageInfoBean> imageInfoList = new ArrayList<ImageInfoBean>();
        if (datas != null && datas.size() > 0) {
            for (Map<String, String> map : datas) {
                String photoname = map.get("FILENAME");

                String path = photoUtil.getSavePath(photoname);

                ImageInfoBean im = new ImageInfoBean(photoname.replace(".jpg", ""), path, path);

                imageInfoList.add(im);
            }
        }
        moudleListener.onInitData(datas, imageInfoList);
    }

    @Override
    public void savePhoto(String imageName, String beizhu) {

    }

    public interface TzpPhotoMoudleListener {
        void onInitData(List<Map<String, String>> datas, List<ImageInfoBean> imageInfoList);
    }
}
